import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:untitled1/main.dart';

class LoginPage extends ConsumerStatefulWidget {
  const LoginPage({super.key});
  @override
  ConsumerState<ConsumerStatefulWidget> createState() => _LoginPage();
}

class _LoginPage extends ConsumerState<LoginPage> {
  @override
  Widget build(BuildContext context) {
    var homeState = ref.watch(homeProviders);
    return Scaffold(
      appBar: AppBar(
        title: const Text("我是主页2"),
      ),
      body: Column(
        children: [
          ...homeState.countList.map((e) {
            return Container(
              alignment: Alignment.center,
              width: 100,
              height: 20,
              margin: const EdgeInsets.all(20),
              color: Colors.white54,
              child: Text(
                "$e",
                style: const TextStyle(fontSize: 16),
              ),
            );
          }).toList(),
          Center(
            child: Text('${homeState.count}'),
          ),
          GestureDetector(
            onTap: () async {
              await ref.read(homeProviders.notifier).removeOne();
            },
            child: Container(
              width: 100,
              height: 30,
              color: Colors.red.shade100,
              child: const Text("点击修改数组第一个值"),
            ),
          ),
          Text(homeState.student.name ?? ""),
          Text(homeState.student.id.toString()),
          Container(
            color: Colors.green,
            width: 100,
            height: 100,
            child: const Text("页面2"),
          ),
        ],
      ),
    );
  }
}
